﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Autenticacao
{
    public partial class ConsultasInserir_Exp : Form
    {
        System.Data.SqlClient.SqlConnection con;

        public Exploracao ex2;
        private int num5;
        
        public ConsultasInserir_Exp(Exploracao ex1,  int num, string nomec, string chip)
        {
            this.ex2 = ex1;
            this.num5 = num;

            InitializeComponent();
            txtnomecli.Text = nomec;
            txtnchip.Text = chip;
        }

        private void cmdi_cons_Click(object sender, EventArgs e)
        {
            if (txtdata.Text == "" || txtdata.Text == "aaaa/MM/dd" || txthora.Text == "" || txthora.Text == "HH:mm" || txtanam.Text == "" || txtdiagno.Text == "" || txtpeso.Text == "" || txttemp.Text == "" || txttrat.Text == "")
                MessageBox.Show("Deve preencher todos os campos da consulta", "Faltam dados", MessageBoxButtons.OK, MessageBoxIcon.Information);
            else
            {
                con = new System.Data.SqlClient.SqlConnection();
                con.ConnectionString = @"Data Source = ANDRÉ-PC\SQLEXPRESS; Initial Catalog = horsepw_bd; Integrated Security = True;";
                con.Open();

                string tipo = "Animal Exploracao";
                SqlCommand command1 = con.CreateCommand();
                command1.CommandText = "Insert into Consulta (data_consulta, hora_consulta, tipo_consulta, anamenese, diagnostico, tratamento, pre_peso, pre_temperatura, id_animal) values ('" + txtdata.Text + "', '" + txthora.Text + "', '" + tipo + "', '" + txtanam.Text + "', '" + txtdiagno.Text + "', '" + txttrat.Text + "', '" + txtpeso.Text + "', '" + txttemp.Text + "', " + num5 + ")";
                command1.CommandType = CommandType.Text;
                SqlDataReader reader1 = command1.ExecuteReader();
                con.Close();

                MessageBox.Show("Consulta inserida com sucesso!", "Consulta inserida", MessageBoxButtons.OK, MessageBoxIcon.Information);

                this.Close();
            }
        }

        private void cmdf_cons_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}
